/**
 * 
 */
package com.hson.demo.base.util.web;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.commons.lang.StringUtils;

/**
 * @author Hungel zou
 * @time 2014年7月28日 下午6:28:34
 */
public class PropertiesUtil {

	//private static final String TWSKEPS = "twskeps.properties";
	//private static final String FTP = "ftp.properties";
	private static final String COMMON = "common.properties";
	
	public static Properties getProperties(String propertyName){
		Properties pro = new Properties();
		InputStream fis = null;
		try{
			fis = PropertiesUtil.class.getClassLoader().getResourceAsStream((propertyName));
			if (fis != null){
				pro.load(fis);
				return pro;
			}
		} catch(Exception e){
			e.printStackTrace();
		} finally{
			if (fis != null) {
				try {
					fis.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return null;
	}
	
//	public static Properties getProperties(){
//		return getProperties(TWSKEPS);
//	}
//	
//	public static Properties getFtpProperties(){
//		return getProperties(FTP);
//	}
	
	public static Properties getCommonProperties(){
		return getProperties(COMMON);
	}
	
	public static String getProperty(String key) {
		if (getCommonProperties() != null) {
			return getCommonProperties().getProperty(key);
		}
		return null;
	}
	
	public static Integer getProperty4Int(String key){
		String s = getProperty(key);
		if (StringUtils.isNotBlank(s)) {
			try {
				return Integer.parseInt(s);
			} catch(NumberFormatException e){
				//
			}
		}
		return null;
	}
	
	public static void main(String[] args){
		System.out.println(getProperty("image.path"));
	}
	
}
